//
//  ConclusionCollectionView.swift
//  SidebarMenu
//
//  Created by LiangXiaobin on 2017/2/3.
//  Copyright © 2017年 AppCoda. All rights reserved.
//

import UIKit

class ConclusionCollectionView: UIView,UICollectionViewDelegate,UICollectionViewDataSource {

    var collectionView:UICollectionView?
    
    override init(frame: CGRect) {
        super.init(frame: frame)

        let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = UICollectionViewScrollDirection.vertical  //滚动方向
        layout.itemSize = CGSize(width:300, height:235)
        
        collectionView = UICollectionView(frame:CGRect(x:0,y:0,width:self.frame.width,height:self.frame.height), collectionViewLayout:layout)
        collectionView?.backgroundColor = UIColor.white
        collectionView?.delegate = self
        collectionView?.dataSource = self
        collectionView?.register(UINib(nibName: "ConclusionCollectionViewCell", bundle: Bundle.main), forCellWithReuseIdentifier: "ConclusionCollectionViewCell")
        self.addSubview(collectionView!)

    }
    
    
    // CollectionView行数
    func collectionView(_ collectionView: UICollectionView,
                        numberOfItemsInSection section: Int) -> Int {
        return 6;
    }
    
    // 获取单元格
    func collectionView(_ collectionView: UICollectionView,
                        cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        // storyboard里设计的单元格
        let identify:String = "ConclusionCollectionViewCell"
        // 获取设计的单元格，不需要再动态添加界面元素
        let cell = self.collectionView?.dequeueReusableCell(
            withReuseIdentifier: identify, for: indexPath) as! ConclusionCollectionViewCell
        
        return cell
    }

    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
